package com.xinqi.common.base.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xinqi.common.base.enums.YesNoEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 题目内容DTO,大家都用这个，如果有改动的地方，大家只需要改一个地方就行了
 *
 * @author linkai
 * @date 2023/3/26
 */
@Data
@Schema(description = "试题基础信息DTO")
public class QuestionBaseDTO implements Serializable {
    /**
     * 题目唯一标记
     */
    @JsonProperty("id")
    @Schema(description = "题目唯一标记", example = "1")
    private Long id;
    /**
     * 题型，1:判断题；2:单选题；3:多选题；4:不定项题；5: 填空题；6:简答题；
     */
    @JsonProperty("type")
    @Schema(description = "题型，1:判断题；2:单选题；3:多选题；4:不定项题；5: 填空题；6:简答题；", example = "1")
    private String type;
    /**
     * 标题
     */
    @Schema(description = "标题", example = "")
    @Size(min = 0, max = 3000, message = "题目字数不能大于3000")
    private String question;
    /**
     * 内容
     */
    @Schema(description = "内容", example = "")
    @Size(min = 0, max = 3000, message = "内容字数不能大于3000")
    private String content;

    /**
     * 题干文件
     */
    private String questionFile;
    /**
     * 题目文件
     */
    @Schema(description = "内容文件列表", example = "")
    private List<CommonFileDTO> questionFiles;

    /**
     * 选项设置
     */
    private String options;
    /**
     * 选项设置
     */
    @Schema(description = "选项设置", example = "")
    private List<QuestionOptionsDTO> optionList;
    /**
     * 难易程度，1:易；2:中；3:难
     */
    @Schema(description = "难易程度，1:易；2:中；3:难", example = "")
    private String difficulty;
    /**
     * 分值
     */
    @Schema(description = "分值", example = "")
    private BigDecimal score;
    /**
     * 题目排序
     */
    @Schema(description = "题目排序", example = "")
    private Integer sort;

    /**
     * 答案
     */
    @Schema(description = "答案", example = "")
    @Size(min = 0, max = 1000, message = "答案字数不能大于1000")
    private String answer;
    /**
     * 答案文件
     */
    @Schema(description = "答案文件", example = "")
    private String answerFile;
    /**
     * 答案文件
     */
    @Schema(description = "答案文件列表", example = "")
    private List<CommonFileDTO> answerFiles;

    /**
     * 答案解析
     */
    @Schema(description = "答案解析", example = "")
    @Size(min = 0, max = 1000, message = "答案解析字数不能大于1000")
    private String analysis;
    /**
     * 答案解析
     */
    @Schema(description = "答案解析文件", example = "")
    private String analysisFile;
    /**
     * 答案解析文件
     */
    @Schema(description = "答案解析文件列表", example = "")
    private List<CommonFileDTO> analysisFiles;

    /**
     * 获取正确的选项
     */
    public List<String> rightOptions() {
        return optionList.stream()
            .filter(p -> p.getSelected().equals(YesNoEnum.YES.ordinal()))
            .map(QuestionOptionsDTO::getId)
            .collect(Collectors.toList());
    }
}
